package com.moteur.analysersite.httpRequestResponse;

import java.util.ArrayList;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

//http://www.mkyong.com/java/how-to-get-http-response-header-in-java/
@SuppressWarnings("deprecation")
public class ResponseHeaderUtil {
	private String url;
	private ArrayList<String> noeuds;
	
	
	 public ResponseHeaderUtil() {
		super();
		this.noeuds =  new ArrayList<String>();
	}
	 
	 public ResponseHeaderUtil(String url) {
		super();
		this.url = url;
		this.noeuds =  new ArrayList<String>();
	}

	public String getUrl() {
		return url;
	}


	public void setUrl(String url) {
		this.url = url;
	}


	public ArrayList<String> getNoeuds() {
		return noeuds;
	}


	public void setNoeuds(ArrayList<String> noeuds) {
		this.noeuds = noeuds;
	}

	public ArrayList<String> lancer(){
		try {

			HttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet(url);
			HttpResponse response = client.execute(request);
			Header[] headers = response.getAllHeaders();
			for (Header header : headers) {
				this.noeuds.add(header.getName()+": "+header.getValue());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return this.noeuds;
	}
}
